package com.restaurant.web.android.service;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.restaurant.domain.Menucategory;
import com.restaurant.service.MenucategoryService;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

@Component
@RequestMapping("/loadAllMenucategory.do")
public class MenuCategoryController {
	
	private final String queryLoadAllMenucategory = "from Menucategory where isdeleted = false";
	
	@Autowired
	private MenucategoryService objMenucategoryService;
	
	@RequestMapping(method = RequestMethod.POST)
	public void menuCategoryControllerPOSTRequest(HttpServletRequest request, HttpServletResponse response){
		XStream objXStream = new XStream(new DomDriver());
		objXStream.alias("menucategory", Menucategory.class);
		objXStream.alias("list", List.class);
		
		try {
			String xml = objXStream.toXML(objMenucategoryService.loadByHql(queryLoadAllMenucategory));
			response.getWriter().print(xml);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
